log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\META-ANALYSIS AND PUBLICATION BIAS\REVISION FOR RESEARCH SYNTHESIS METHODS\PROGRAMS\TABLE4FEneg.smcl", replace
// This program takes about 19 hours to run on a standard laptop
etime, start
drop _all
clear
graph drop _all
set more off
set seed 13
matrix FAT = J(9,2,0)
matrix PETFPP = J(9,2,0)
local studies = 1000
// Select is used to set the probability of being included in the data set
// when the study is subject to publication bias, either because (i) abs(tstat) < 2, or
// coef < 0. 
local select = 0.10
local obs = 100
// Simulations are set to 5 initially, which takes 6-7 minutes to run.
// To match the results in the paper, change to 10,000, but note that the
// program takes about 10 days to run with this many replications.
local reps = 1000

local i = 1
foreach alpha in 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 {
simulate	 pvalue_FAT = r(pvalue_FAT) N = r(N) ///
	 pvalue_PETFPP = r(pvalue_PETFPP) effect_FPP = r(effect_FPP) pvalue_FPP = r(pvalue_FPP) , ///
               reps(`reps'): FEpbias, alpha(`alpha') studies(`studies') select(`select') obs(`obs') 

	summ N, meanonly
matrix FAT[`i',1] = r(mean)/1000
generate RRFAT = 0
replace RRFAT = cond(pvalue_FAT<0.05,1,0) 
summ RRFAT, meanonly
matrix FAT[`i',2] = r(mean)

summ N, meanonly
matrix PETFPP[`i',1] = r(mean)/1000
generate RRPETFPP = 0
replace RRPETFPP = cond(pvalue_PETFPP<0.05,1,0) 
summ RRPETFPP, meanonly
matrix PETFPP[`i',2] = r(mean)

				
local `++i'
}

matrix colnames FAT = Percent FAT
matrix rownames FAT = A0 A0P5 A1 A1P5 A2 A2P5 A3 A3P5 A4
matrix colnames PETFPP = Percent PET
matrix rownames PETFPP = A0 A0P5 A1 A1P5 A2 A2P5 A3 A3P5 A4
matrix list FAT
matrix list PETFPP

etime

log close
